/** \file utils.h \brief Macros and definitions if not defined in the operation system
 */

#ifndef _UTILS_H_
#define _UTILS_H_

#include <stdlib.h>

#ifdef _MSC_VER
#include <windows.h>
#endif	// _MSC_VER

#ifdef __cplusplus
extern "C" {
#endif

#ifndef min
	/** A macro that returns the minimum of a and b if not defined in Operation System. */
        #define min(a,b)        ((a) <= (b) ? (a) : (b))
#endif

#ifndef max
	/** A macro that returns the maximum of a and b if not defined in Operation System. */
        #define max(a,b)        ((a) >= (b) ? (a) : (b))
#endif

#ifndef TRUE
	/** Define TRUE if not defined in Operation System. */
	#define TRUE 1
#endif

#ifndef FALSE
	/** Define FALSE if not defined in Operation System. */
	#define FALSE 0
#endif

#ifdef LINUX
typedef char TCHAR;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef long LONG;
typedef int BOOL;
typedef void *HANDLE;
typedef char *LPSTR;
typedef char *LPTSTR;
typedef const char *LPCSTR;
typedef const char *LPCTSTR;
typedef wchar_t *LPWSTR;
typedef const wchar_t *LPCWSTR;
typedef void *HMODULE;
typedef DWORD WPARAM;
typedef DWORD LPARAM;
typedef void *HINSTANCE;

typedef void (*LPPostCallback)(void *lpContext, UINT uMsg, WPARAM, LPARAM);
typedef UINT (*LPSendCallback)(void *lpContext, UINT uMsg, WPARAM, LPARAM);
/// for caller callback
typedef struct SHwndContext
{
	/// context of caller
	void	*m_lpContext;
	/// callback, fast return
	LPPostCallback	m_lpfnPost;
	/// callback, need retval
	LPSendCallback	m_lpfnSend;
	/// module startup path(folder name)
	const char	*m_szModule;
	/// file load path(folder name)
	const char	*m_szLoad;
}*HWND;

#define far

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l)           ((WORD)(l))
#define HIWORD(l)           ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w)           ((BYTE)(w))
#define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))

#ifndef MB_OK
#define MB_OK 0
#endif	// MB_OK

#define O_BINARY 0

#define MAX_PATH 256
#define WINAPI
#define CALLBACK
#define __cdecl
#define UNREFERENCED_PARAMETER(x) x

typedef struct tagPoint {
	int	x;
	int	y;
}POINT;

typedef struct tagRect {
	int	left;
	int	top;
	int	right;
	int	bottom;
}RECT;

typedef struct tagSize {
	int	cx;
	int	cy;
}SIZE;

#endif	// LINUX

#ifdef __cplusplus
}; //extern "C"
#endif


#endif	// _UTILS_H_
